/**
 * Created by asen on 2015/10/14.
 */
package com.shoes.controller;

import com.shoes.service.TestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping(value="/index")
public class TestController {

    private TestService testService;

    @RequestMapping(value="/hello")
    public String testController(Model model) {
        model.addAttribute("message", "hello");
        return "hello";
    }

    @RequestMapping(value="/username", method= RequestMethod.GET)
    public String testUserName(Model model, HttpServletRequest request) {
        try {
            String idStr = request.getParameter("id");
            long id = 1;
            if(idStr != null) {
                id = Long.parseLong(idStr);
            }
            String username = testService.testGetUserName(id);
            model.addAttribute("message", username);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "hello";
    }

    public TestService getTestService() {
        return testService;
    }
    @Autowired
    public void setTestService(TestService testService) {
        this.testService = testService;
    }
}